package com.itheima.service.severlimpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.PageBean;
import com.itheima.domain.dto.ArraySLists;
import com.itheima.domain.dto.ArraysList;
import com.itheima.domain.pojo.TCheckItem;
import com.itheima.mapper.TCustomerMapper;
import com.itheima.service.TCustomerSerevce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class TCustomerSerevceImpl implements TCustomerSerevce {
    @Autowired
    private TCustomerMapper tCustomerMapper;

    @Override
    public PageBean selectAll(Integer page, Integer size, String name,String phone, Short gender, LocalDate beginTime, LocalDate endTime) {
        PageHelper.startPage(page, size);
        Page<TCheckItem> page1 = tCustomerMapper.selectAll(page,size,name,phone,gender,beginTime,endTime);
        return new PageBean(page1.getTotal(),page1.getResult());
    }

    @Override
    public ArraySLists s1() {
        List<ArraysList> arraysList = tCustomerMapper.s1();
        ArraySLists arraySLists = new ArraySLists();
        List<String> arrayList1 = new ArrayList<>();
        List<Integer> arrayList2 = new ArrayList<>();
        for (ArraysList list : arraysList) {
            arrayList1.add(list.getAgeGroupList());
            arrayList2.add(list.getAgeCountList());
        }
        arraySLists.setAgeGroupList(arrayList1);
        arraySLists.setAgeCountList(arrayList2);
        return arraySLists;
    }
}
